import Vue from "vue";
import Router from "vue-router";
/*
import Login from "../page/Login/Login.vue";
import Index from "../page/Index/Index.vue";
import Cash from "../page/Cash/Cash.vue";
import Check from "../page/Check/Check.vue";
import Diamond from "../page/Diamond/Diamond.vue";
import Activity from "../page/Activity/Activity.vue";
*/
import DhLayout from "../frame/template/Layout.vue";
import Agent from "../page/Index/subpage/Agent";
import Tixian from "../page/Cash/page/tixian.vue";
import TixianRecord from "../page/Cash/page/record.vue";
import CheckIndex from "../page/Check/subpage/Index.vue"
import QinYou from "../page/Index/subpage//QinYou.vue"
import UserStatic from '../page/Index/subpage/UserStatic'
import Group from "../page/Check/subpage/Group"
import GroupMenberDetail from '../page/Check/subpage/GroupMenberDetail'

import Record from "../page/Check/subpage/Record"
import QinYouCount from "../page/Check/subpage/QinYouCount";
import My from "../page/My/My";
import EditPass from "../page/Edit/Password";
import ZuanSiYujin from "../page/Edit/ZuansiYujin";
import GameId from "../page/Edit/GameId";
import RecordDetail from "../page/Check/subpage/RecordDetail";
import MyGet from '../page/Diamond/MyGet'



import ChargeDetail from '../page/Userstatistics/ChargeDetail'
import UserQuery from '../page/Userstatistics/UserQuery'
import PaijuQuery from '../page/Userstatistics/PaijuQuery'
import Charge from '../page/Userstatistics/Charge'
import FenCheng from '../page/Userstatistics/FenCheng'


import RankInfo from '../page/Other/RankInfo.vue'
import Help from '../page/Other/Help'
import FenchengInfo from '../page/Other/FenchengInfo.vue'
import EditUpLimit from '../page/Edit/EditUpLimit'

import ClubHelp from '../page/Other/ClubHelp'
/**
 * 活动
 */

import ThreeActive from "../page/Activity/ThreeActive";
import OpenRoom from "../page/Activity/OpenRoom";
/**
 * 活动
 */
const Login = () =>
    import ( /* webpackChunkName: "group-foo" */ "../page/Login/Login.vue");
const Index = () =>
    import ( /* webpackChunkName: "group-foo" */ "../page/Index/Index.vue");
const Cash = () =>
    import ( /* webpackChunkName: "group-fooo" */ "../page/Cash/Cash.vue");
const Check = () =>
    import ( /* webpackChunkName: "group-fooo" */ "../page/Check/Check.vue");
const Activity = () =>
    import ( /* webpackChunkName: "group-fooo" */ "../page/Activity/Activity.vue");

const Diamond = () =>
    import ( /* webpackChunkName: "group-fooo" */ "../page/Diamond/Diamond.vue");

const GiveAgentDiamond = () =>
    import ( /* webpackChunkName: "group-fooo" */ "../page/Diamond/GiveAgentDiamond.vue");
Vue.use(Router);
const Foo = () => Promise.resolve({ /* 组件定义对象 */ })
const router = new Router({
    //  mode: 'history',
    routes: [
        { path: "/", redirect: "/home" },
        {
            path: "/login",
            name: "Login",
            component: Login,

        },
        {
            path: "/clubhelp",
            name: "lubHelp",
            component: ClubHelp,

        },
        {
            path: "/home",
            name: "首页",
            component: Index,
            meta: { requiresAuth: true }
        },
        {
            path: "/cash", //提现
            component: Cash,
            // redirect: '/cash/index',
            meta: { requiresAuth: true },
            children: [{
                    path: "",
                    component: Tixian,
                    name: "提现",

                },
                {
                    path: "index",
                    component: Tixian,
                    name: "提现"
                },
                {
                    path: "record",
                    component: TixianRecord,
                    name: "提现记录"
                }
            ]
        },
        {
            path: "/qinyou",
            component: QinYou,
            meta: { requiresAuth: true }
        },
        {
            path: "/check", //审核
            component: Check,
            meta: { requiresAuth: true },
            children: [{
                    path: "",
                    component: CheckIndex,
                    name: "审核"
                }, {
                    path: "record",
                    component: Record,
                    name: "亲友战绩",

                }, {
                    path: "detail/:id",
                    component: RecordDetail,
                    name: "战绩详情",

                }, {
                    path: "group",
                    component: Group,
                    name: "亲友群"
                },
                {
                    path: "memberdetail/:Id",
                    component: GroupMenberDetail,
                    name: "成员详情"
                },
                {
                    path: "count",
                    component: QinYouCount,
                    name: "统计"
                }
            ]
        },
        {
            path: "/diamond", //赠送用户钻石
            component: Diamond,
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/diamond/:Id", //赠送用户钻石
            component: Diamond,
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/giveagentdiamond", //赠送代理商钻石
            component: GiveAgentDiamond,
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/myget", //赠送代理商钻石
            component: MyGet,
            meta: { requiresAuth: true },
            children: []

        },
        {
            path: "/activity", //活动
            component: Activity,
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/agent", //活动
            component: Agent,
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/my", //活动
            component: My,
            name: "个人设置",
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/editpass", //活动
            component: EditPass,
            meta: { requiresAuth: true },
            name: "修改密码",
            children: []
        },
        {
            path: "/editdia", //活动
            component: ZuanSiYujin,
            name: "修改钻石预警",
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/eidtuplimit/:Id", //活动
            component: EditUpLimit,
            name: "修改游戏局数",
            meta: { requiresAuth: true },
            children: []
        },
        {
            path: "/editgameid", //活动
            component: GameId,
            name: "修改游戏ID",
            meta: { requiresAuth: true },
            children: []
        },
        {

            path: "/detail/:id",
            component: RecordDetail,
            meta: { requiresAuth: true },
            name: "战绩详情",

        },
        //统计
        {
            path: "/userstatic",
            component: UserStatic,
            meta: { requiresAuth: true },
            name: "统计报表",
        },
        {
            path: "/userquery",
            component: UserQuery,
            meta: { requiresAuth: true },
            name: "用户查询",
        },
        {
            path: "/paijuquery",
            component: PaijuQuery,
            meta: { requiresAuth: true },
            name: "牌桌查询",
        },
        {
            path: "/chargerecord",
            meta: { requiresAuth: true },
            component: Charge,
            name: "消费充值记录",
        },
        {
            path: "/chargedetail/:time/:id",
            meta: { requiresAuth: true },
            component: ChargeDetail,
            name: "消费记录详情",

        },
        {
            path: "/fenchengrecord",
            meta: { requiresAuth: true },
            component: FenCheng,
            name: "分成统计",
        },
        {
            path: "/rankinfo",
            component: RankInfo,
            meta: { requiresAuth: true },
            name: "代理升级说明",
        },
        {
            path: "/help",
            component: Help,
            meta: { requiresAuth: true },
            name: "帮助说明",
        },
        {
            path: "/fenchenginfo",
            component: FenchengInfo,
            meta: { requiresAuth: true },
            name: "帮助说明",
        },
        {
            path: "/threeactive",
            component: ThreeActive,
            meta: { requiresAuth: true },
            name: "三日活动",
        },
        {
            path: "/openroom",
            component: OpenRoom,
            meta: { requiresAuth: true },
            name: "三日活动",
        }
    ]
});

var auth = true;
router.beforeEach((to, from, next) => {
    // console.log(to);
    // console.log(from);
    let autho = to.matched.some(record => record.meta.requiresAuth);
    if (autho) {
        // console.log(true);
        // this route requires auth, check if logged in
        // if not, redirect to login page.

        if (!sessionStorage.getItem('Ticket')) {
            // console.log('token  不存在');
            next({
                path: "/login",
                query: { redirect: to.fullPath } //把要跳转的地址作为参数传到下一步
            });
        } else {
            next();
        }
    } else {
        next(); // 确保一定要调用 next()
    }
});

export default router;